<!DOCTYPE html>
<html>
<head lang="en">
	<meta charset="UTF-8">
	<title>Ajax Example</title>
</head>
<body>
<center />
<h1>Loading a web page into a DIV</h1>
<div id="info">This sentence will be replaced</div>
<script>
	params = 'url=oreilly.com'
	request = new ajaxRequest()
	request.open('POST', 'urlpost.php', true)	//服务器端脚本
	request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')	//如果使用GET方式请求调用上面的open方法，就不需要用下面三行发送标题了
	request.setRequestHeader('Content-length', params.length)
	request.setRequestHeader('Connection', 'close')

	request.onreadystatechange = function(){
		if(this.readyState == 4){
			if(this.status == 200){
				if(this.responseText != null){
					document.getElementById('info').innerHTML = this.responseText
				}
				else{
					alert('Ajax error: No data received')
				}
			}
			else{
				alert('Ajax error:' + this.statusText)
			}
		}

	}

	request.send(params)

	function ajaxRequest(){
		try{
			var request = new XMLHttpRequest()	//非IE
		}
		catch(e1){
			request = false
		}

		return request
	}

</script>
</body>
</html>